<%--
  Created by IntelliJ IDEA.
  User: ASUS
  Date: 2021/12/17
  Time: 15:44
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>员工信息</title>
    <link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/layui/layui.js"></script>
</head>
<body>
<%--头部搜索栏--%>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <div class="layui-input-inline">
                <input type="text" name="staffname" placeholder="请输入员工姓名"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <input type="text" name="staffid"  placeholder="请输入员工工号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <select name="branchid" lay-search="" id="branchTid">
                    <option value="">门店</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="search">搜索</button>
            </div>
        </div>
    </div>
</form>


<table class="layui-hide" id="test" lay-filter="test"></table>

<%--修改的form--%>
<form class="layui-form" style="display: none;width: 400px;height: 400px" id="Staff" lay-filter="Staff" >
    <input type="hidden" name="id"/>
    <div class="layui-form-item">
        <label class="layui-form-label"  >员工工号:</label>
        <div class="layui-input-block">
            <input type="text" name="staffid" lay-verify="required" autocomplete="off" placeholder="员工工号" class="layui-input" readonly>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">员工姓名:</label>
        <div class="layui-input-block">
            <input type="text" name="staffname" lay-verify="required" autocomplete="off" placeholder="请输入员工姓名" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">身份证号:</label>
        <div class="layui-input-block">
            <input type="text" name="idcard" lay-verify="pass" readonly  placeholder="请输入身份证号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">地址:</label>
        <div class="layui-input-block">
            <input type="text" name="address" lay-verify="pass"  placeholder="请输入地址" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号:</label>
        <div class="layui-input-block">
            <input type="text" name="phone" lay-verify="pass"  placeholder="请输入手机号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">入职时间:</label>
        <div class="layui-input-block">
            <input type="text" name="entrytime" lay-verify="pass" readonly  placeholder="请输入入职时间" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">店铺:</label>
        <div class="layui-input-block">
            <%--name的值必须和实体类的对应。--%>
            <select name="branchid" lay-search="" id="branch_id" disabled>
                <option value="">选择店名</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">职位:</label>
        <div class="layui-input-block">
            <%--name的值必须和实体类的对应。--%>
            <select name="roleid" lay-search="" id="role_id"  disabled>
                <option value="">选择职位</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">部门类型:</label>
        <div class="layui-input-block">
            <%--name的值必须和实体类的对应。--%>
            <select name="deptid" lay-search="" id="dept_id"  disabled>
                <option value="">选择部门类型</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" lay-submit="" lay-filter="demo">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<%--添加的form--%>
<form class="layui-form" style="display: none;width: 400px;height: 400px" id="StaffAdd" lay-filter="StaffAdd" >
    <input type="hidden" name="url" id="url"/>
    <div class="layui-form-item">
        <label class="layui-form-label"  >员工工号:</label>
        <div class="layui-input-block">
            <input type="text" name="staffid" id="addstaffid" lay-verify="staffid" autocomplete="off" placeholder="员工工号" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">员工姓名:</label>
        <div class="layui-input-block">
            <input type="text" id="staffname" name="staffname" lay-verify="required" autocomplete="off" placeholder="请输入员工姓名" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码:</label>
        <div class="layui-input-block">
            <input type="password" name="password" lay-verify="pass"  placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">身份证号:</label>
        <div class="layui-input-block">
            <input type="text" id="idcard" name="idcard" lay-verify="Idcard"  placeholder="请输入身份证号" autocomplete="off" class="layui-input" >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">地址:</label>
        <div class="layui-input-block">
            <input type="text" name="address" lay-verify="pass"  placeholder="请输入地址" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机号:</label>
        <div class="layui-input-block">
            <input type="text" id="phone" name="phone" lay-verify="phone"  placeholder="请输入手机号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" style="display: none">
        <label class="layui-form-label">状态:</label>
        <div class="layui-input-block">
            <input type="text" name="state" lay-verify="pass" autocomplete="off" class="layui-input" readonly value="1">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">店名:</label>
        <div class="layui-input-block">
            <%--name的值必须和实体类的对应。--%>
            <select name="branchid" lay-search="" id="addbranch_id" >
                <option value="">选择店名</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">职位:</label>
        <div class="layui-input-block">
            <%--name的值必须和实体类的对应。--%>
            <select name="roleid" lay-search="" id="addrole_id" lay-verify="droleid" >
                <option value="">选择职位</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-upload">
            <button type="button" class="layui-btn" id="test1">上传图片</button>
            <div class="layui-upload-list">
                <img class="layui-upload-img" id="demo1" style="width: 80px;height: 80px;border: 1px solid #f3f3f3">
                <p id="demoText"></p>
            </div>
            <div style="width: 95px;">
                <div class="layui-progress layui-progress-big" lay-showpercent="yes" lay-filter="urldemo">
                    <div class="layui-progress-bar" lay-percent=""></div>
                </div>
            </div>
        </div>
        <a name="list-progress"> </a>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" lay-submit="" lay-filter="adddemo">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<%--调动form--%>
<form class="layui-form" style="display: none;width: 400px;height: 400px" id="editstaff" lay-filter="editstaff"  >
    <div class="layui-form-item">
        <label class="layui-form-label"  >员工工号:</label>
        <div class="layui-input-block">
            <input type="text" name="staffid" lay-verify="required" autocomplete="off" placeholder="员工工号" class="layui-input" readonly>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">员工姓名:</label>
        <div class="layui-input-block">
            <input type="text" name="staffname" lay-verify="required" autocomplete="off" placeholder="请输入员工姓名" class="layui-input" readonly>
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">旧店名:</label>
        <div class="layui-input-inline">
            <select name="branchid" lay-search="" id="oldbranchid" disabled>
                <option value="">选择店名</option>
            </select>
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">旧部门名:</label>
        <div class="layui-input-inline">
            <select name="deptid" lay-search="" id="olddeptid" disabled>
                <option value="">部门名</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item" style="padding-top: 5px">
        <label class="layui-form-label">店名:</label>
        <div class="layui-input-block">
            <%--name的值必须和实体类的对应。--%>
            <select name="newbranchid" lay-search="" id="branchid" readonly>
                <option value="">选择店名</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">部门类型:</label>
        <div class="layui-input-block">
            <%--name的值必须和实体类的对应。--%>
            <select name="newdeptid" lay-search="" id="deptid"  readonly>
                <option value="">选择部门类型</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" lay-submit="" lay-filter="editstaffdemo">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>


<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    {{#  if(d.branchid == 12138){ }}
    {{#  if(d.roleid == 1){ }}
    <h2 style="color: #ff0000;font-weight: bolder;margin-left: 72px">总店长</h2>
    {{#  } else { }}
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs layui-btn-normal" id="transfer1"  lay-event="transfer">调动</a>
    {{#  if(d.state == 1){ }}
    <button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="updateState">离职</button>
    {{#  } else if(d.state == 0) { }}
    <button class="layui-btn layui-btn-xs " lay-event="updateState">上岗</button>
    {{#  } else { }}
    <button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="updateState">离职</button>
    {{#  } }}
    {{#  if(d.state == 1){ }}
    <a class="layui-btn layui-btn-xs layui-btn-normal" id="DongJie"  lay-event="DongJie">冻结</a>
    {{#  } else { }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" id="JieDong"  lay-event="JieDong">解冻</a>
    {{#  } }}
    {{#  } }}
    {{#  } else { }}
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs layui-btn-normal" id="transfer"  lay-event="transfer">调动</a>
    {{#  if(d.state == 1){ }}
    <button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="updateState">离职</button>
    {{#  } else if(d.state == 0) { }}
    <button class="layui-btn layui-btn-xs " lay-event="updateState">上岗</button>
    {{#  } else { }}
    <button class="layui-btn layui-btn-xs layui-btn-danger" lay-event="updateState">离职</button>
    {{#  } }}
    {{#  if(d.state == 1){ }}
    <a class="layui-btn layui-btn-xs layui-btn-normal" id="DongJie1"  lay-event="DongJie">冻结</a>
    {{#  } else { }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" id="JieDong1"  lay-event="JieDong">解冻</a>
    {{#  } }}
    {{#  } }}

</script>
<script>
    layui.use(['table','form','jquery','layer','element'], function() {
        var table = layui.table;
        var form = layui.form;
        var $=layui.jquery;
        var layer=layui.layer;
        var upload=layui.upload;
        var element=layui.element;


        /*员工id验证*/
        $("#addstaffid").bind("input",function(){
            //$("#deptname").blur(function () {
            // })
            $.post("${pageContext.request.contextPath}/staff/FindStaffid",{"staffid":$("#addstaffid").val()},function (backdata) {
                if (backdata.code==1){//编号不重复
                    sub=0;
                }else {//编号重复
                    sub=sub+1;
                    layer.msg('已被占用，请重新填写',{icon: 5})
                }
            }, 'json')
        });

        //员工工号验证
        form.verify({
            staffid:function(value, item){ //value：表单的值、item：表单的DOM对象
                var staffid=$("#addstaffid").val();
                var message = '';
                $.ajax({
                    url: "${pageContext.request.contextPath}/staff/FindStaffid",
                    data:{"staffid":staffid},
                    async:false,
                    dataType:'json',
                    success:function (result){
                        if (result.code==1){//编号不重复
                        }else {//编号重复
                            message ="员工号已存在，请重新输入！"
                        }
                    }
                })
                if (message != '') {
                    return message;
                }
            }
        });

        //员工职位验证
        form.verify({
            droleid:function(value, item){ //value：表单的值、item：表单的DOM对象
                var branchid=$("#addbranch_id").val();
                var addrolid=$("#addrole_id").val();
                var message = '';
                if (addrolid==1){
                    $.ajax({
                        url: "${pageContext.request.contextPath}/staff/position",
                        data:{"branchid":branchid},
                        async:false,
                        dataType:'json',
                        success:function (result){
                            if (result.code==0){//编号不重复
                            }else {//编号重复
                                message ="该店已存在店长，请重新输入！"
                            }
                        }
                    })
                    if (message != '') {
                        return message;
                    }
                }
            }

        });

        /*员工手机号校验校验*/
        form.verify({
            phone: function(value, item){ //value：表单的值、item：表单的DOM对象
                var phone = $("#phone").val()
                var message = '';
                let regs = /^((13[0-9])|(17[0-1,6-8])|(15[^4,\\D])|(18[0-9]))\d{8}$/;
                if (!regs.test(value)) {
                    return '手机号格式有误！';
                }
                $.ajax({
                    url: "${pageContext.request.contextPath}/staff/getStaffPhone",
                    type: 'post',
                    data:{"phone":phone},
                    async:false,
                    dataType:'json',
                    success:function (result){
                        if (result.code==1){//编号不重复
                        }else {//编号重复
                            message ="手机号已存在，请重新输入！"
                        }
                    }
                })
                if (message != '') {
                    return message;
                }
            }
        });

        /*员工身份证号校验校验*/
        form.verify({
            Idcard: function(value, item){ //value：表单的值、item：表单的DOM对象
                var idcard = $("#idcard").val()
                var message = '';
                var regs = /^(\d{18,18}|\d{15,15}|\d{17,17}X)$/;
                if (!regs.test(value)) {
                    return '身份证号格式有误！';
                }
                $.ajax({
                    url: "${pageContext.request.contextPath}/staff/getStaffIdcard",
                    type: 'post',
                    data:{"idcard":idcard},
                    async:false,
                    dataType:'json',
                    success:function (result){
                        if (result.code==1){//编号不重复
                        }else {//编号重复
                            message ="身份证号已存在，请重新输入！"
                        }
                    }
                })
                if (message != '') {
                    return message;
                }
            }
        });


        window.onload=function (){ //页面加载完毕后执行的函数$(function(){})
            getAllBranch();
            getAllRole();
            getAllDept();
        }
        function getAllBranch(){
            $.ajax({
                url:"${pageContext.request.contextPath}/branch/findAll",
                typeP:"post",
                async:false,//ajax异步交互，async：false是同步提交
                success:function (result) {
                    var type=result.data;
                    var str="<option value=''>选择门店</option>";
                    for (var i = 0; i < type.length; i++) {
                        str+="<option value='"+type[i].branchid+"'>"+type[i].branchname+"</option>"
                    }
                    $("#branchTid").html(str);
                    $("#branch_id").html(str);
                    $("#addbranch_id").html(str);
                    $("#branchid").html(str);
                    $("#oldbranchid").html(str);
                    form.render('select'); //让form表单的select标签渲染
                },
                dataType:'json'
            });
        }
        function getAllRole(){
            $.ajax({
                url:"${pageContext.request.contextPath}/role/SelectAll",
                typeP:"post",
                async:false,//ajax异步交互，async：false是同步提交
                success:function (result) {
                    var type=result.data;
                    var str="<option value=''>选择职位</option>";
                    for (var i = 0; i < type.length; i++) {
                        str+="<option value='"+type[i].roleid+"'>"+type[i].rolename+"</option>"
                    }
                    $("#role_id").html(str);
                    $("#addrole_id").html(str);
                    form.render('select'); //让form表单的select标签渲染
                },
                dataType:'json'
            });
        }
        function getAllDept(){
            $.ajax({
                url:"${pageContext.request.contextPath}/dept/findAll",
                typeP:"post",
                async:false,//ajax异步交互，async：false是同步提交
                success:function (result) {
                    var type=result.data;
                    var str="<option value=''>选择部门</option>";
                    for (var i = 0; i < type.length; i++) {
                        str+="<option value='"+type[i].deptid+"'>"+type[i].deptname+"</option>"
                    }
                    $("#dept_id").html(str);
                    $("#adddept_id").html(str);
                    $("#deptid").html(str);
                    $("#olddeptid").html(str);
                    form.render('select'); //让form表单的select标签渲染
                },
                dataType:'json'
            });
        }

        //头像上传
        //常规使用 - 普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: '${pageContext.request.contextPath}/upload' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                    console.log(result)
                });
                element.progress('demo', '0%'); //进度条复位
                layer.msg('上传中', {icon: 16, time: 0});
            }
            ,done: function(res){
                //如果上传失败
                if(res.code===5000){
                    return layer.msg('上传失败');
                }
                //上传成功的一些操作. 隐藏域 把上传的图片路径随着表单的提交而被提交到后台。
                $("#url").val(res.data);
                $('#demoText').html(''); //置空上传失败的状态
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #ff5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
            //进度条
            ,progress: function(n, elem, e){
                element.progress('demo', n + '%'); //可配合 layui 进度条元素使用
                if(n == 100){
                    layer.msg('上传完毕', {icon: 1});
                }
            }
        });

        //添加表单的搜索监听事件
        form.on('submit(search)',function(data){
            //表格数据重新渲染。
            table.reload('test',{
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: { //按照什么进行查找
                    "staffname": data.field.staffname,
                    "staffid": data.field.staffid,
                    "branchid": data.field.branchid
                }
            })
        });

        //监听头部工具栏
        table.on('toolbar(test)',function (obj) {
            var event=obj.event;
            if (event==='add'){
                $("#StaffAdd")[0].reset();
                layer.open({
                    type:1,
                    area:['400px','400px'],
                    content: $("#StaffAdd"),
                    titlel:'添加员工'
                })
            }
        });


        ////监听行工具事件
        table.on('tool(test)',function (obj) {
            var data=obj.data
                ,$=layui.jquery
                ,form=layui.form;
            if(obj.event==='edit'){
                var leave=0;
                if(data.staffid!=${sessionScope.staff.staffid} && data.branchid==${sessionScope.staff.branchid}){
                    leave=1;
                }
                if(499==${sessionScope.staff.staffid}){
                    leave=1;
                }
                if(leave==1){
                    layer.open({
                        type: 1
                        ,id:'bookId'//防止重复弹出
                        , content:$('#Staff')
                        ,btnAlign:'c'//按钮居中
                        ,area:['360px','400px']
                        ,shade:0 //不显示遮罩
                    });
                }else {
                    layer.msg("只能编辑本店铺的员工");
                }
                //回显数据到表单，Food对应的是form表单里的lay-filter的值
                form.val('Staff',data);
            }else if(obj.event==='transfer'){
                var move=1;
                $.ajax({
                    url:"${pageContext.request.contextPath}/transferstaffstaff/geteditIngstaff",
                    data:{"staffid":obj.data.staffid},
                    async:false,
                    dataType:'json',
                    success:function (result){
                        if (result.code==2){//编号不重复
                            layer.msg("该员工正在调动！")
                            move = 1;
                        }else {//编号重复
                            move = 0;
                        }
                    }
                })
                if(data.staffid==${sessionScope.staff.staffid}){
                    layer.msg("自己无法调动自己！")
                    move = 1;
                }
                if(data.branchid!=${sessionScope.staff.branchid}){
                    layer.msg("无法调动其他部门！")
                    move = 1;
                }
                if(data.roleid==1 && 499!=${sessionScope.staff.staffid}){
                    layer.msg("该成员为店长，无法调动！")
                    move = 1;
                }
                if(move==0){
                    layer.open({
                        type: 1
                        ,id:'bookId1'//防止重复弹出
                        , content:$('#editstaff')
                        ,btnAlign:'c'//按钮居中
                        ,area:['360px','500px']
                        ,shade:0 //不显示遮罩
                    })
                };
                //回显数据到表单，Food对应的是form表单里的lay-filter的值
                form.val('editstaff',data);
            } else if(obj.event==='updateState'){
                var leave=0;
                if(data.staffid!=${sessionScope.staff.staffid} && data.branchid==${sessionScope.staff.branchid}){
                    leave=1;
                }
                if(499==${sessionScope.staff.staffid}){
                    leave=1;
                }
                if(leave==1){
                        layer.confirm('真的要切换离职么', function(index){
                            $.ajax({
                                url: "${pageContext.request.contextPath}/staff/updateState",
                                data: obj.data,
                                type: "post",
                                success: function(result){
                                    if(result.code===2000){
                                        //关闭弹窗
                                        layer.closeAll();
                                        //弹出一号表情
                                        layer.msg(result.msg,{icon: 1});
                                        //刷新表格
                                        table.reload('test');
                                    }else{
                                        layer.msg(result.msg,{icon:5});
                                    }
                                },
                                dataType:"json"
                            })
                        })
                }else {
                    layer.msg("不是相同店铺并且本人不可以离职本人哦")
                }
            }else if(obj.event==='DongJie'){
                var leave=0;
                if(data.staffid!=${sessionScope.staff.staffid} && data.branchid==${sessionScope.staff.branchid}){
                    leave=1;
                }
                if(499==${sessionScope.staff.staffid}){
                    leave=1;
                }
                if(leave==1){
                    layer.confirm('要冻结该员工吗', function(index){
                        $.ajax({
                            url: "${pageContext.request.contextPath}/staff/Dongjie",
                            data: obj.data,
                            type: "post",
                            success: function(result){
                                if(result.code===2000){
                                    //关闭弹窗
                                    layer.closeAll();
                                    //弹出一号表情
                                    layer.msg(result.msg,{icon: 1});
                                    //刷新表格
                                    table.reload('test');
                                }else{
                                    layer.msg(result.msg,{icon:5});
                                }
                            },
                            dataType:"json"
                        })
                    })
                }else {
                    layer.msg("不是相同店铺并且本人不可以冻结本人哦")
                }

            }else if(obj.event==='JieDong'){
                var leave=0;
                if(data.staffid!=${sessionScope.staff.staffid} && data.branchid==${sessionScope.staff.branchid}){
                    leave=1;
                }
                if(499==${sessionScope.staff.staffid}){
                    leave=1;
                }
                if(leave==1){
                    layer.confirm('要解冻该员工吗', function(index){
                        $.ajax({
                            url: "${pageContext.request.contextPath}/staff/JieDong",
                            data: obj.data,
                            type: "post",
                            success: function(result){
                                if(result.code===2000){
                                    //关闭弹窗
                                    layer.closeAll();
                                    //弹出一号表情
                                    layer.msg(result.msg,{icon: 1});
                                    //刷新表格
                                    table.reload('test');
                                }else{
                                    layer.msg(result.msg,{icon:5});
                                }
                            },
                            dataType:"json"
                        })
                    })
                }
            }else {
                layer.msg("没有权限解冻")
            }
        });
        //修改
        form.on('submit(demo)',function (data) {
                $.ajax({
                    url: "${pageContext.request.contextPath}/staff/edit",
                    data:data.field,
                    type:"post",
                    success: function(result){
                        if(result.code===2000){
                            //关闭弹窗
                            layer.closeAll();
                            //弹出一号表情
                            layer.msg(result.msg,{icon: 1});
                            //刷新表格
                            table.reload('test');
                        }else{
                            layer.msg(result.msg,{icon:5});
                        }
                    },
                    dataType:"json"
                })

        });


        //添加
        form.on('submit(adddemo)',function (data) {
                $.ajax({
                    url: "${pageContext.request.contextPath}/staff/StaffAdd",
                    data:data.field,
                    type:"post",
                    success: function(result){
                        if(result.code===2000){
                            //关闭弹窗
                            layer.closeAll();
                            //弹出一号表情
                            layer.msg(result.msg,{icon: 1});
                            //刷新表格
                            table.reload('test');
                        }else{
                            layer.msg(result.msg,{icon:5});
                        }
                    },
                    dataType:"json"
                })
        });

        //表单的提交事件 demo1表示button的lay-filter属性的值
        //平调
        form.on('submit(editstaffdemo)',function (data) {

                $.ajax({
                    url: "${pageContext.request.contextPath}/transferstaffstaff/editstaff",
                    data:data.field,
                    type:"post",
                    success: function(result){
                        if(result.code===2000){
                            //关闭弹窗
                            layer.closeAll();
                            //弹出一号表情
                            layer.msg(result.msg,{icon: 1});
                            //刷新表格
                            table.reload('test');
                        }else{
                            layer.msg(result.msg,{icon:5});
                        }
                    },
                    dataType:"json"
                })

        });

        table.render({
            elem: '#test'
            // ,id:"test"
            , url: '${pageContext.request.contextPath}/staff/listByCondition'
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , title: '员工数据表'
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'staffid', title: '员工工号',  sort: true}
                , {field: 'staffname', title: '员工姓名'}
                , {field: 'idcard', title: '身份证号码' }
                , {field: 'address', title: '地址'}
                , {field: 'phone', title: '电话号码'}
                , {field: 'entrytime', title: '入职时间'}
                , {field: 'branchid', title: '店名',templet:function (a) {
                        return a.branch==null?"":a.branch.branchname;
                    }}
                , {field: 'roleid', title: '职位',templet:function (b) {
                        return b.role==null?"待定":b.role.rolename;
                    }}
                , {field: 'deptid', title: '部门名称',templet:function (c) {
                        return c.dpm==null?"":c.dpm.deptname;
                    }}
                , {field: 'state', title: '状态',templet:function (d) {
                        return d.state==1?
                            "<button class='layui-btn layui-btn-sm'>正在工作</button>":d.state==2?"<a class='layui-btn layui-btn-xs layui-btn-normal'>已冻结</a>":"";
                    }
                }
                , {fixed: 'right', title: '操作', toolbar: '#barDemo',width:270}
            ]]
            , page: true
            , limit: 4 //默认每页显示5条
            , limits:[2,4,10,15]
        });
    });
</script>
</body>
</html>
